package com.tongcao.cn.algorithm.designMoel.proxy.jdk.cglib.demo;

import org.mockito.cglib.proxy.MethodInterceptor;
import org.mockito.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @author:tongcao
 * @since:2019/6/18 19:47
 * Description:
 */
public class CGlibProxyInteceptor implements MethodInterceptor {


    /**
     * @param sub         cglib生成的代理对象
     * @param method      被代理对象方法
     * @param objects     方法入参
     * @param methodProxy 代理方法
     * @return
     * @throws Throwable
     */
    @Override
    public Object intercept(Object sub, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("执行前...");
        Object object = methodProxy.invokeSuper(sub, objects);
        System.out.println("执行后...");
        return object;
    }
}